package com.candy.service.impl;

import com.candy.bean.Car;
import com.candy.dao.CarMapper;
import com.candy.service.CarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

@Service
public class CarServiceImpl implements CarService {
    @Autowired
    CarMapper carMapper;

    /**
     * 查询未删除状态下的用户信息
     * @param car
     * @return
     */
    @Override
    public List<Car> getAllCars(Car car) {
        List<Car> carInfos=carMapper.getAllCars(car);
        return carInfos;
    }

    /**
     * 新增或修改操作；根据主键id是否为空判断是新增还是编辑
     * @param car
     * @return
     */
    @Override
    public Integer addOrUpdateCar(@RequestBody Car car) {
        Integer id=car.getId();
        Integer num;
        if(id==null||id.equals("")){
            num=carMapper.insertSelective(car);
        }else{
            num=carMapper.updateByPrimaryKeySelective(car);
        }
        return num;
    }

    /**
     * 删除操作：采用逻辑删除实现此目的。通过改变isdeleted的值来修改用户状态
     * @param car
     * @return
     */
    @Override
    public Integer deleteCar(Car car) {
        car.setIsdelete(1);
        Integer num=carMapper.updateByPrimaryKeySelective(car);
        return num;
    }
}
